import store from '@/store'
/**
 * @author yang xiao xing 
 * @param {Array} value
 * @returns {Boolean}
 * @example =>
 * <div v-permission="['admin']" class="permission-sourceCode" type="info">
 *  v-permission="['admin']"
 * </div>
 */
export default function hasPermission(value = []) {
    if (value && value instanceof Array && value.length > 0) {
        let storeRoles = (store.getters && store.getters.userRoles) || [];
        let hasPermission = storeRoles.some(item => {
            return value.includes(item);
        });
        return hasPermission;
    } else {
        console.error(`需要角色! 例如 v-permission="['admin','editor']"`)
        return false
    }
}